/**
 * @desc '钱包'页面
 */

const state = {
  isVisible: true,
  tabIndex: 0,
  theTabOffset: 0
}

const getters = {
  currMonthList(state, getters, rootState) {
    const currMonth = new Date().getMonth()
    return rootState.TheBook.table.filter(v => {
      const month = new Date(v.date).getMonth()
      return month === currMonth
    })
  },

  days(state, getters, rootState) {
    const table = rootState.TheBook.table
    if (!table.length) {
      return 0
    }
    const firstDay = table[0].date
    const lastDay = table[table.length - 1].date
    return Math.ceil((lastDay - firstDay) / (1000 * 60 * 60 * 24))
  }
}

const mutations = {
  handleVisible(state) {
    state.isVisible = !state.isVisible
  },

  handleTab(state, index) {
    state.tabIndex = index
  },

  handleTabOffset(state, top) {
    state.theTabOffset = top
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations
}
